-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use CommandExt::exec for cargo run
on Unix (#2343)
#2818
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Thanks for the PR @robinst! The implementation looks good to me. cc @brson, do you have thoughts on this? This causes the behavior on Windows and Unix to diverge, but in a way that makes sense to me because this is arguably the "more correct" thing to do and allows native tools like gdb and such to work if you want to debug the target process. I also suspect that we may want rustup to start taking a similar tactic where it uses |
@alexcrichton I recall that at least in the rustup case we decided to move back to fork/exec for a reason more than consistency with windows ... telemetry. Can't report anything if your process doesn't exist. The problem of killing cargo transitively killing rustc can be solved in some other way too right? |
Ah right, forgot about the telemetry. In Cargo's case it can't report things like termination-via-signal on Unix where it can do more fancy reporting on Windows if we implement this. It's true that transitively killing rustc is possible on Unix with process groups (you kill the entire process group, not just the Cargo process). It's somewhat of a pain to set up though and it also doesn't allow things like debuggers/profilers to work nicely, so I don't necessarily see process killing as the only motivation here. I'm somewhat inclined to do this as this seems a little more low level than what rustup is doing, but it also would likely have far less utility unless rustup mirrored this strategy (as I guess there's no other way to collect telemetry in rustup? |
ping @brson, although this is deviating Cargo and rustup, I feel like for Cargo this is still the right choice, how do you feel about that? |
I'm kinda confused on the issues here. Doesn't killing cargo today kill the child too? I thought that was standard behavior - on windows isn't that why we have the explicit group setup - so that killing cargo kills rustc?
Why does this patch affect the reporting on Windows? It's a Unix-specific patch. |
@brson on Unix if you kill Cargo's process group you will kill the child too, and if you want to kill Cargo then you should always do that as we're never, for example, going to
Today, Cargo will print out whether the child abnormally terminated, e.g. a segfault. This happens for Windows as well. If, however, Cargo were to |
On Unix. Are you just suggesting that if we made this change on Unix we would also remove the reporting behavior on Windows so they have feature-parity? |
Oh sorry nah I was actually just pointing out how this will introduce an inconsistency between Unix/Windows. It's probably not worth it to actively avoid printing such information on Windows when we otherwise could. |
☔ The latest upstream changes (presumably #3091) made this pull request unmergeable. Please resolve the merge conflicts. |
Should I look into fixing the conflicts for this PR? I probably should have explained why I created this PR: I was looking for nice way to have auto-reloading when developing server programs (e.g. an iron server).
What happens is that With this PR, it works nicely as expected. So, what I currently use to get the auto reloading is entr (it manages to kill both cargo and the child process): |
@robinst thanks for the ping! Sorry this PR has been a bit slow :( In that specific case For a tool like Basically the tl;dr; is that I don't think this feature is appropriate for solving the The drawback is that while this functionality would work on Unix, none of it would work on Windows (due to the lack of exec). This means that you could have an inconsistent development experience across platforms, which is generally something we try to avoid where possible. I'm still a bit on the fence about whether or not it's worth it here. I believe @brson felt that it may have not been, but I'm not sure whether I agree yet. So I guess to answer your question about whether this should be rebased or not, first off do you agree with what I mentioned about |
Apparently I'll rebase this PR, and maybe look into doing the process group thing in Also note that just recently the watchexec tool was released, and it has the same problem: watchexec/watchexec#16 |
4f6b278
to
f301522
Compare
Before, we would spawn a child process for the program. One of the problems with that is when killing the cargo process, the program continues running. With this change, the cargo process is replaced by the program, and killing it works.
f301522
to
ed5cea5
Compare
@bors: r+ |
📌 Commit ed5cea5 has been approved by |
Use CommandExt::exec for `cargo run` on Unix (#2343) Before, we would spawn a child process for the program. One of the problems with that is when killing the cargo process, the program continues running. With this change, the cargo process is replaced by the program, and killing it works. Before (`cargo run` is the parent): > 502 7615 7614 0 2:26PM ttys012 0:00.12 /Users/rstocker/.multirust/toolchains/stable-x86_64-apple-darwin/bin/cargo run > 502 7620 7615 0 2:26PM ttys012 0:00.01 target/debug/program After (the shell is the parent): > 502 81649 81648 0 5:27PM ttys012 0:00.69 -zsh > 502 7739 81649 0 2:26PM ttys012 0:01.27 target/debug/program
Ok, I think this is worth it for the debugging and "least surprise" case, so r+'ing. Thanks again! |
☀️ Test successful - cargo-cross-linux, cargo-linux-32, cargo-linux-64, cargo-mac-32, cargo-mac-64, cargo-win-gnu-32, cargo-win-gnu-64, cargo-win-msvc-32, cargo-win-msvc-64 |
Thanks for merging this! Saw that the 2017 roadmap includes "Rust should have a pleasant edit-compile-debug cycle", and that is exactly what motivated this PR. I now use watchexec like so for server development:
It still takes 7 seconds to compile after I've made changes, but it's already better than manually restarting (and here's hoping that incremental compilation will bring down those 7 seconds in the future) :). Ideally I'd want |
Before, we would spawn a child process for the program. One of the
problems with that is when killing the cargo process, the program
continues running.
With this change, the cargo process is replaced by the program, and
killing it works.
Before (
cargo run
is the parent):After (the shell is the parent):